package www.ld.com.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import www.ld.com.entities.Dept;
import www.ld.com.service.IDeptService;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    private IDeptService deptService;

    @GetMapping("/findAll")
    public List<Dept> findAll() {
        return deptService.findAll();
    }

    @GetMapping("test/{id}")
    //一旦调用服务方法失败并抛出错误信息后,会自动调用@HystrixCommand标注好的fallbackMethod调用类中的指定方法
    @HystrixCommand(fallbackMethod = "processHystrix")
    public String test(@PathVariable("id") Long id) {
        if (id > 10)
            throw new RuntimeException("哦哦！我就是试试Hystrix");
        return "成功";
    }

     //参数不行和@HystrixCommand一直
    public String processHystrix(@PathVariable("id") Long id) {
        return "测试Hystrix 调用失败！ 哦哦+id:"+id;
    }
}
